package card2;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;



public class CardMethod {

    private final String[] suits = {"♥", "♠", "♣", "♦"};

    // 买牌
    public List<Card> buy() {
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(suits[i], j);
                cards.add(card);
            }
        }
        return cards;
    }
    // 洗牌
    public void  shuffle(List<Card> cards) {
        Random random = new Random();
        for (int i = cards.size() - 1 ; i > 0; i--) {
            int index = random.nextInt(i);
            swap(cards, index, i);
        }
    }

    private void swap(List<Card> cards, int index, int i) {
        Card tempCard = cards.get(index);
        cards.set(index,cards.get(i));
        cards.set(i,tempCard);
    }

    // 揭牌
    public void getCard(List<Card> cards) {
        List<Card> hands1 = new ArrayList<>();
        List<Card> hands2 = new ArrayList<>();
        List<Card> hands3 = new ArrayList<>();

        List<List<Card>> people = new ArrayList<>();
        people.add(hands1);
        people.add(hands2);
        people.add(hands3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < people.size(); j++) {
                Card card = cards.remove(i);
                people.get(j).add(card);
            }
        }

        System.out.println("第1个揭牌如下：");
        System.out.println(hands1);
        System.out.println("第2个揭牌如下：");
        System.out.println(hands2);
        System.out.println("第3个揭牌如下：");
        System.out.println(hands3);

        System.out.println("剩下的牌：");
        System.out.println(cards);

    }
} 
